package com.link.base.base.authproduct.controller;

import com.link.base.base.authproduct.model.AuthProduct;
import com.link.base.base.authproduct.model.AuthProductQuery;
import com.link.base.base.authproduct.service.AuthProductService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liushoulong
 * @date 2018-11-06
 * @desc 授权单品controller
 */
@Controller("AuthProductController")
@RequestMapping("/link/authProduct")
public class AuthProductController extends BasicController<AuthProduct> {

    @Resource
    private AuthProductService authProductService;

    @Override
    public BasicService<AuthProduct> getBasicService() throws Exception {
        return authProductService;
    }

    /**
     * 传入产品列表，批量生成授权单品记录
     */
    @RequestMapping(value = "/batchInsertByProdList")
    @ResponseBody
    public Map<String, Object> batchInsertByProdList(@JsonParam QueryParams qps, @JsonParam AuthProductQuery authProductQuery, HttpSession session,
                                                     HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(6);
        try {
            authProductService.batchInsertByProdList(authProductQuery);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

}
